package com.zw.pm.module.config.factory;

import com.zw.pm.gen.entity.Factory;
import com.zw.pm.gen.mapper.FactoryMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

import static com.zw.pm.constant.Constant.STATUS_NORMAL;

/**
 * @Description: 分厂 服务
 *
 * @Author: China.sgl
 * @Date: 2019/12/6 08:42
 */
@Service
@Slf4j
public class FactoryService {

    @Autowired
    private FactoryMapper factoryMapper;
    @Autowired
    private FactoryDao factoryDao;

    /**
     * 按条件查询
     * @param factory factory
     * @return list
     */
    public List<Factory> findFactoryAll(Factory factory) {
        return factoryDao.findFactoryAll(factory);
    }

    /**
     * 修改
     *
     * @param factory factory
     * @return 影响行数
     */
    public int updateFactory(Factory factory) {
        return factoryMapper.updateByPrimaryKeySelective(factory);
    }

    /**
     * 按分厂名称查询
     *
     * @param name name
     * @return Factory
     */
    public Factory findByFactoryName(String name) {
        return factoryDao.findByFactoryName(name);
    }

    /**
     * 保存分厂信息
     *
     * @param factory factory
     * @return 影响行数
     */
    public int saveFactory(Factory factory) {
        factory.setStatus(STATUS_NORMAL);
        factory.setCreateTime(new Date());
        return factoryMapper.insert(factory);
    }

    /**
     * 根据ID查询
     * @param id id
     * @return Factory
     */
    public Factory getFactory(Integer id) {
        return factoryMapper.selectByPrimaryKey(id);
    }

    /**
     * 删除
     *
     * @param factory factory
     * @return 影响行数
     */
    public int delFactory(Factory factory) {
        return factoryMapper.updateByPrimaryKeySelective(factory);
    }
}
